package com.example.qqviewspringboot.repository;

import com.example.qqviewspringboot.data.Friendship;
import com.example.qqviewspringboot.data.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

    @Query("SELECT u FROM User u WHERE LOWER(u.username) = LOWER(:username)")
    Optional<User> findByUsernameIgnoreCase(@Param("username") String username);

    List<User> findAll();

    @Query("SELECT u FROM User u JOIN Friendship f ON u.id = f.userId WHERE f.friendId = :userId AND f.status = :status")
    List<User> findUsersByPendingRequests(@Param("userId") Long userId, @Param("status") Friendship.Status status);
    // 根据用户名查找用户
    Optional<User> findByUsername(String username);

    // 根据用户名和密码查找用户
    Optional<User> findByUsernameAndPassword(String username, String password);

}
